package com.mjlf.proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @ClassName Proxy
 * @auther mjlf
 * @Date 2019/9/18 15:50
 * @Description 代理类
 */
public class Proxy implements InvocationHandler {

    private Object target;

    public Proxy(Object target) {
        this.target = target;
    }

    /**
     * 执行代理方法
     * @param proxy
     * @param method
     * @param args
     * @return
     * @throws Throwable
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("startTime : " + System.currentTimeMillis());
        Object result = method.invoke(target, args);
        System.out.println("endTime : " + System.currentTimeMillis());

        return result;
    }
}
